using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using NTTHAO.CommonWeb;
using NTTHAO.Web.BL.Product;
using System.IO;

public partial class admin_webparts_Plug_ins_Product_ProductTypeConfig : System.Web.UI.UserControl
{
    public bool _IsAdmin = false;
    public ProductGroup _Group = null;
    public ProductTypeConfig _ParentConfig = null;
    public ProductTypeConfig _Config = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        this.btnSave.Text = this.btnSave2.Text = LanguageUtility.GetLanguageText("SAVE", Session);
        this._IsAdmin = "admin".Equals(Context.User.Identity.Name, StringComparison.OrdinalIgnoreCase);

        if (!this._IsAdmin && "0".Equals(Request.QueryString["typeid"], StringComparison.OrdinalIgnoreCase))
        {
            Response.Redirect("ProductContent.aspx?action=err&err=notauthorised", false);
            return;
        }

        if (!IsPostBack)
        {
            int langID = LanguageUtility.GetLanguageID(Request, Session);
            int siteID = WebGlobal.GetSite().ID;

            txtPresentativeImage.Text = LanguageUtility.GetLanguageText("PRESENTATIVE_IMAGE", Session);
            txtImage1.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 1";
            txtImage2.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 2";
            txtImage3.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 3";
            txtImage4.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 4";
            txtImage5.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 5";
            txtImage6.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 6";
            txtImage7.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 7";
            txtImage8.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 8";
            txtImage9.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 9";
            txtImage10.Text = LanguageUtility.GetLanguageText("IMAGE", Session) + " 10";
            try
            {
                int groupID = Int32.Parse(Request.QueryString["g"].Trim());
                _Group = new ProductGroup(groupID);

                DataTable tbType = ProductPropertyType.GetAll(siteID, langID);
                if (tbType != null)
                {
                    cmbProp1Type.DataSource
                        = cmbProp2Type.DataSource
                        = cmbProp3Type.DataSource
                        = cmbProp4Type.DataSource
                        = cmbProp5Type.DataSource
                        = cmbProp6Type.DataSource
                        = cmbProp7Type.DataSource
                        = cmbProp8Type.DataSource
                        = cmbProp9Type.DataSource
                        = cmbProp10Type.DataSource
                        = tbType;
                    cmbProp1Type.DataTextField
                        = cmbProp2Type.DataTextField
                        = cmbProp3Type.DataTextField
                        = cmbProp4Type.DataTextField
                        = cmbProp5Type.DataTextField
                        = cmbProp6Type.DataTextField
                        = cmbProp7Type.DataTextField
                        = cmbProp8Type.DataTextField
                        = cmbProp9Type.DataTextField
                        = cmbProp10Type.DataTextField
                        = ProductPropertyType.NAME__COLUMN_NAME;
                    cmbProp1Type.DataValueField
                        = cmbProp2Type.DataValueField
                        = cmbProp3Type.DataValueField
                        = cmbProp4Type.DataValueField
                        = cmbProp5Type.DataValueField
                        = cmbProp6Type.DataValueField
                        = cmbProp7Type.DataValueField
                        = cmbProp8Type.DataValueField
                        = cmbProp9Type.DataValueField
                        = cmbProp10Type.DataValueField
                        = ProductPropertyType.ID__COLUMN_NAME;
                    cmbProp1Type.DataBind();
                    cmbProp2Type.DataBind();
                    cmbProp3Type.DataBind();
                    cmbProp4Type.DataBind();
                    cmbProp5Type.DataBind();
                    cmbProp6Type.DataBind();
                    cmbProp7Type.DataBind();
                    cmbProp8Type.DataBind();
                    cmbProp9Type.DataBind();
                    cmbProp10Type.DataBind();
                }

                DataTable tbTypeColl = ProductPropertyCollection.GetAll(siteID, langID, 1);
                if (tbTypeColl != null)
                {
                    cmbProp1TypeColl.DataSource
                        = cmbProp2TypeColl.DataSource
                        = cmbProp3TypeColl.DataSource
                        = cmbProp4TypeColl.DataSource
                        = cmbProp5TypeColl.DataSource
                        = cmbProp6TypeColl.DataSource
                        = cmbProp7TypeColl.DataSource
                        = cmbProp8TypeColl.DataSource
                        = cmbProp9TypeColl.DataSource
                        = cmbProp10TypeColl.DataSource
                        = tbTypeColl;
                    cmbProp1TypeColl.DataTextField
                        = cmbProp2TypeColl.DataTextField
                        = cmbProp3TypeColl.DataTextField
                        = cmbProp4TypeColl.DataTextField
                        = cmbProp5TypeColl.DataTextField
                        = cmbProp6TypeColl.DataTextField
                        = cmbProp7TypeColl.DataTextField
                        = cmbProp8TypeColl.DataTextField
                        = cmbProp9TypeColl.DataTextField
                        = cmbProp10TypeColl.DataTextField
                        = ProductPropertyCollection.NAME__COLUMN_NAME;
                    cmbProp1TypeColl.DataValueField
                        = cmbProp2TypeColl.DataValueField
                        = cmbProp3TypeColl.DataValueField
                        = cmbProp4TypeColl.DataValueField
                        = cmbProp5TypeColl.DataValueField
                        = cmbProp6TypeColl.DataValueField
                        = cmbProp7TypeColl.DataValueField
                        = cmbProp8TypeColl.DataValueField
                        = cmbProp9TypeColl.DataValueField
                        = cmbProp10TypeColl.DataValueField
                        = ProductPropertyCollection.ID__COLUMN_NAME;
                    cmbProp1TypeColl.DataBind();
                    cmbProp2TypeColl.DataBind();
                    cmbProp3TypeColl.DataBind();
                    cmbProp4TypeColl.DataBind();
                    cmbProp5TypeColl.DataBind();
                    cmbProp6TypeColl.DataBind();
                    cmbProp7TypeColl.DataBind();
                    cmbProp8TypeColl.DataBind();
                    cmbProp9TypeColl.DataBind();
                    cmbProp10TypeColl.DataBind();
                }

                DataTable tbMultiValueType = ProductPropertyMultiValueType.GetAll(siteID, langID);
                if (tbMultiValueType != null)
                {
                    cmbProp1TypeMulti.DataSource
                        = cmbProp2TypeMulti.DataSource
                        = cmbProp3TypeMulti.DataSource
                        = cmbProp4TypeMulti.DataSource
                        = cmbProp5TypeMulti.DataSource
                        = cmbProp6TypeMulti.DataSource
                        = cmbProp7TypeMulti.DataSource
                        = cmbProp8TypeMulti.DataSource
                        = cmbProp9TypeMulti.DataSource
                        = cmbProp10TypeMulti.DataSource
                        = tbMultiValueType;
                    cmbProp1TypeMulti.DataTextField
                        = cmbProp2TypeMulti.DataTextField
                        = cmbProp3TypeMulti.DataTextField
                        = cmbProp4TypeMulti.DataTextField
                        = cmbProp5TypeMulti.DataTextField
                        = cmbProp6TypeMulti.DataTextField
                        = cmbProp7TypeMulti.DataTextField
                        = cmbProp8TypeMulti.DataTextField
                        = cmbProp9TypeMulti.DataTextField
                        = cmbProp10TypeMulti.DataTextField
                        = ProductPropertyMultiValueType.NAME__COLUMN_NAME;
                    cmbProp1TypeMulti.DataValueField
                        = cmbProp2TypeMulti.DataValueField
                        = cmbProp3TypeMulti.DataValueField
                        = cmbProp4TypeMulti.DataValueField
                        = cmbProp5TypeMulti.DataValueField
                        = cmbProp6TypeMulti.DataValueField
                        = cmbProp7TypeMulti.DataValueField
                        = cmbProp8TypeMulti.DataValueField
                        = cmbProp9TypeMulti.DataValueField
                        = cmbProp10TypeMulti.DataValueField
                        = ProductPropertyMultiValueType.ID__COLUMN_NAME;
                    cmbProp1TypeMulti.DataBind();
                    cmbProp2TypeMulti.DataBind();
                    cmbProp3TypeMulti.DataBind();
                    cmbProp4TypeMulti.DataBind();
                    cmbProp5TypeMulti.DataBind();
                    cmbProp6TypeMulti.DataBind();
                    cmbProp7TypeMulti.DataBind();
                    cmbProp8TypeMulti.DataBind();
                    cmbProp9TypeMulti.DataBind();
                    cmbProp10TypeMulti.DataBind();
                }

                int typeID = 0;
                if (Request.QueryString["typeid"] != null)
                {
                    Int32.Parse(Request.QueryString["typeid"].Trim());
                }
                _Config = ProductTypeConfig.GetConfigByType(_Group.ID, typeID);
                if (_Config == null)
                {
                    _Config = new ProductTypeConfig();
                }
                else
                {
                    txtPresentativeImage.Text = _Config.Image;
                    txtImage1.Text = _Config.Image_1;
                    txtImage2.Text = _Config.Image_2;
                    txtImage3.Text = _Config.Image_3;
                    txtImage4.Text = _Config.Image_4;
                    txtImage5.Text = _Config.Image_5;
                    txtImage6.Text = _Config.Image_6;
                    txtImage7.Text = _Config.Image_7;
                    txtImage8.Text = _Config.Image_8;
                    txtImage9.Text = _Config.Image_9;
                    txtImage10.Text = _Config.Image_10;
                }

                chkUnitVisible.Checked = _Config.UnitVisible;
                chkSaleOffVisible.Checked = _Config.SaleOffVisible;
                chkSoldOutVisible.Checked = _Config.SoldOutVisible;

                chkAutoResizePreImage.Checked = _Config.ResizePreImage;
                txtMaxPreImageWidth.Text = _Config.PreImageWidth.ToString();
                txtMaxPreImageHeight.Text = _Config.PreImageHeight.ToString();
                cmbPreImageResizeOption.Value = _Config.PreImageResizeOption.ToString();
                txtPreImageBackColor.Text = _Config.PreImageBackColor;

                chkAutoResize.Checked = _Config.AutoResizeImage;
                txtMaxImageWidth.Text = _Config.MaxImageWidth.ToString();
                txtMaxImageHeight.Text = _Config.MaxImageHeight.ToString();
                cmbImageResizeOption.Value = _Config.ImageResizeOption.ToString();
                txtImageBackColor.Text = _Config.ImageBackColor;

                chkCreateMiniImage.Checked = _Config.AutoMiniImage;
                txtMiniImageWidth.Text = _Config.MiniImageWidth.ToString();
                txtMiniImageHeight.Text = _Config.MiniImageHeight.ToString();
                cmbMiniImageResizeOption.Value = _Config.MiniImageResizeOption.ToString();
                txtMiniImageBackColor.Text = _Config.MiniImageBackColor;

                cmbNumberOfImage.Value = _Config.NumberOfImage.ToString();

                cmbNumberOfProperty.Value = _Config.NumberOfProperty.ToString();
                txtProperty1.Text = _Config.Property_1;
                txtProperty2.Text = _Config.Property_2;
                txtProperty3.Text = _Config.Property_3;
                txtProperty4.Text = _Config.Property_4;
                txtProperty5.Text = _Config.Property_5;
                txtProperty6.Text = _Config.Property_6;
                txtProperty7.Text = _Config.Property_7;
                txtProperty8.Text = _Config.Property_8;
                txtProperty9.Text = _Config.Property_9;
                txtProperty10.Text = _Config.Property_10;

                cmbProp1Type.Value = _Config.Prop1Type.ToString();
                cmbProp2Type.Value = _Config.Prop2Type.ToString();
                cmbProp3Type.Value = _Config.Prop3Type.ToString();
                cmbProp4Type.Value = _Config.Prop4Type.ToString();
                cmbProp5Type.Value = _Config.Prop5Type.ToString();
                cmbProp6Type.Value = _Config.Prop6Type.ToString();
                cmbProp7Type.Value = _Config.Prop7Type.ToString();
                cmbProp8Type.Value = _Config.Prop8Type.ToString();
                cmbProp9Type.Value = _Config.Prop9Type.ToString();
                cmbProp10Type.Value = _Config.Prop10Type.ToString();

                if (_Config.Prop1Type == 2)
                {
                    cmbProp1TypeColl.Value = _Config.Prop1CollID.ToString();
                }
                else if (_Config.Prop1Type == 3)
                {
                    cmbProp1TypeMulti.Value = _Config.Prop1CollID.ToString();
                }
                if (_Config.Prop2Type == 2)
                {
                    cmbProp2TypeColl.Value = _Config.Prop2CollID.ToString();
                }
                else if (_Config.Prop2Type == 3)
                {
                    cmbProp2TypeMulti.Value = _Config.Prop2CollID.ToString();
                }
                if (_Config.Prop3Type == 2)
                {
                    cmbProp3TypeColl.Value = _Config.Prop3CollID.ToString();
                }
                else if (_Config.Prop3Type == 3)
                {
                    cmbProp3TypeMulti.Value = _Config.Prop3CollID.ToString();
                }
                if (_Config.Prop4Type == 2)
                {
                    cmbProp4TypeColl.Value = _Config.Prop4CollID.ToString();
                }
                else if (_Config.Prop4Type == 3)
                {
                    cmbProp4TypeMulti.Value = _Config.Prop4CollID.ToString();
                }
                if (_Config.Prop5Type == 2)
                {
                    cmbProp5TypeColl.Value = _Config.Prop5CollID.ToString();
                }
                else if (_Config.Prop5Type == 3)
                {
                    cmbProp5TypeMulti.Value = _Config.Prop5CollID.ToString();
                }
                if (_Config.Prop6Type == 2)
                {
                    cmbProp6TypeColl.Value = _Config.Prop6CollID.ToString();
                }
                else if (_Config.Prop6Type == 3)
                {
                    cmbProp6TypeMulti.Value = _Config.Prop6CollID.ToString();
                }
                if (_Config.Prop7Type == 2)
                {
                    cmbProp7TypeColl.Value = _Config.Prop7CollID.ToString();
                }
                else if (_Config.Prop7Type == 3)
                {
                    cmbProp7TypeMulti.Value = _Config.Prop7CollID.ToString();
                }
                if (_Config.Prop8Type == 2)
                {
                    cmbProp8TypeColl.Value = _Config.Prop8CollID.ToString();
                }
                else if (_Config.Prop8Type == 3)
                {
                    cmbProp8TypeMulti.Value = _Config.Prop8CollID.ToString();
                }
                if (_Config.Prop9Type == 2)
                {
                    cmbProp9TypeColl.Value = _Config.Prop9CollID.ToString();
                }
                else if (_Config.Prop9Type == 3)
                {
                    cmbProp9TypeMulti.Value = _Config.Prop9CollID.ToString();
                }
                if (_Config.Prop10Type == 2)
                {
                    cmbProp10TypeColl.Value = _Config.Prop10CollID.ToString();
                }
                else if (_Config.Prop10Type == 3)
                {
                    cmbProp10TypeMulti.Value = _Config.Prop10CollID.ToString();
                }

                txtProp1DefaultValue.Text = _Config.Prop1DefaultValue;
                txtProp2DefaultValue.Text = _Config.Prop2DefaultValue;
                txtProp3DefaultValue.Text = _Config.Prop3DefaultValue;
                txtProp4DefaultValue.Text = _Config.Prop4DefaultValue;
                txtProp5DefaultValue.Text = _Config.Prop5DefaultValue;
                txtProp6DefaultValue.Text = _Config.Prop6DefaultValue;
                txtProp7DefaultValue.Text = _Config.Prop7DefaultValue;
                txtProp8DefaultValue.Text = _Config.Prop8DefaultValue;
                txtProp9DefaultValue.Text = _Config.Prop9DefaultValue;
                txtProp10DefaultValue.Text = _Config.Prop10DefaultValue;
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message + "<br /><br />" + ex.StackTrace);
                //Response.Redirect("ProductContent.aspx?action=view&g=" + Request.QueryString["g"] + "typeid=" + Request.QueryString["typeid"] + "&time=" + DateTime.Now.Ticks.ToString(), false);
            }
        }
    }

    public ProductTypeConfig SaveConfig()
    {
        ProductTypeConfig config = null;
        int groupID = Int32.Parse(Request.QueryString["g"].Trim());
        int typeID = 0;
        if (Request.QueryString["typeid"] != null)
        {
            Int32.Parse(Request.QueryString["typeid"].Trim());
        }

        config = ProductTypeConfig.GetConfigByType(groupID, typeID);
        if (config == null)
        {
            config = new ProductTypeConfig();
            config.GroupID = groupID;
            config.TypeID = typeID;
        }
        config.UnitVisible = chkUnitVisible.Checked;
        config.SaleOffVisible = chkSaleOffVisible.Checked;
        config.SoldOutVisible = chkSoldOutVisible.Checked;

        config.ResizePreImage = chkAutoResizePreImage.Checked;
        config.PreImageWidth = Convert.ToInt32(txtMaxPreImageWidth.Text.Trim());
        config.PreImageHeight = Convert.ToInt32(txtMaxPreImageHeight.Text.Trim());
        config.PreImageResizeOption = Convert.ToInt16(cmbPreImageResizeOption.Value);
        config.PreImageBackColor = txtPreImageBackColor.Text.Trim().Replace("#", "").Substring(0, 6);

        config.AutoResizeImage = chkAutoResize.Checked;
        config.MaxImageWidth = Convert.ToInt32(txtMaxImageWidth.Text.Trim());
        config.MaxImageHeight = Convert.ToInt32(txtMaxImageHeight.Text.Trim());
        config.ImageResizeOption = Convert.ToInt16(cmbImageResizeOption.Value);
        config.ImageBackColor = txtImageBackColor.Text.Trim().Replace("#", "").Substring(0, 6);

        config.AutoMiniImage = chkCreateMiniImage.Checked;
        config.MiniImageWidth = Convert.ToInt32(txtMiniImageWidth.Text.Trim());
        config.MiniImageHeight = Convert.ToInt32(txtMiniImageHeight.Text.Trim());
        config.MiniImageResizeOption = Convert.ToInt16(cmbMiniImageResizeOption.Value);
        config.MiniImageBackColor = txtMiniImageBackColor.Text.Trim().Replace("#", "").Substring(0, 6);

        config.Image = txtPresentativeImage.Text;
        config.NumberOfImage = Int32.Parse(cmbNumberOfImage.Value);
        config.Image_1 = txtImage1.Text;
        config.Image_2 = txtImage2.Text;
        config.Image_3 = txtImage3.Text;
        config.Image_4 = txtImage4.Text;
        config.Image_5 = txtImage5.Text;
        config.Image_6 = txtImage6.Text;
        config.Image_7 = txtImage7.Text;
        config.Image_8 = txtImage8.Text;
        config.Image_9 = txtImage9.Text;
        config.Image_10 = txtImage10.Text;

        config.NumberOfProperty = Int32.Parse(cmbNumberOfProperty.Value);
        config.Property_1 = txtProperty1.Text;
        config.Property_2 = txtProperty2.Text;
        config.Property_3 = txtProperty3.Text;
        config.Property_4 = txtProperty4.Text;
        config.Property_5 = txtProperty5.Text;
        config.Property_6 = txtProperty6.Text;
        config.Property_7 = txtProperty7.Text;
        config.Property_8 = txtProperty8.Text;
        config.Property_9 = txtProperty9.Text;
        config.Property_10 = txtProperty10.Text;

        config.Prop1Type = Convert.ToByte(cmbProp1Type.Value);
        config.Prop2Type = Convert.ToByte(cmbProp2Type.Value);
        config.Prop3Type = Convert.ToByte(cmbProp3Type.Value);
        config.Prop4Type = Convert.ToByte(cmbProp4Type.Value);
        config.Prop5Type = Convert.ToByte(cmbProp5Type.Value);
        config.Prop6Type = Convert.ToByte(cmbProp6Type.Value);
        config.Prop7Type = Convert.ToByte(cmbProp7Type.Value);
        config.Prop8Type = Convert.ToByte(cmbProp8Type.Value);
        config.Prop9Type = Convert.ToByte(cmbProp9Type.Value);
        config.Prop10Type = Convert.ToByte(cmbProp10Type.Value);

        config.Prop1CollID = config.Prop1Type == 3 ? Convert.ToInt32(cmbProp1TypeMulti.Value) : Convert.ToInt32(cmbProp1TypeColl.Value);
        config.Prop2CollID = config.Prop2Type == 3 ? Convert.ToInt32(cmbProp2TypeMulti.Value) : Convert.ToInt32(cmbProp2TypeColl.Value);
        config.Prop3CollID = config.Prop3Type == 3 ? Convert.ToInt32(cmbProp3TypeMulti.Value) : Convert.ToInt32(cmbProp3TypeColl.Value);
        config.Prop4CollID = config.Prop4Type == 3 ? Convert.ToInt32(cmbProp4TypeMulti.Value) : Convert.ToInt32(cmbProp4TypeColl.Value);
        config.Prop5CollID = config.Prop5Type == 3 ? Convert.ToInt32(cmbProp5TypeMulti.Value) : Convert.ToInt32(cmbProp5TypeColl.Value);
        config.Prop6CollID = config.Prop6Type == 3 ? Convert.ToInt32(cmbProp6TypeMulti.Value) : Convert.ToInt32(cmbProp6TypeColl.Value);
        config.Prop7CollID = config.Prop7Type == 3 ? Convert.ToInt32(cmbProp7TypeMulti.Value) : Convert.ToInt32(cmbProp7TypeColl.Value);
        config.Prop8CollID = config.Prop8Type == 3 ? Convert.ToInt32(cmbProp8TypeMulti.Value) : Convert.ToInt32(cmbProp8TypeColl.Value);
        config.Prop9CollID = config.Prop9Type == 3 ? Convert.ToInt32(cmbProp9TypeMulti.Value) : Convert.ToInt32(cmbProp9TypeColl.Value);
        config.Prop10CollID = config.Prop10Type == 3 ? Convert.ToInt32(cmbProp10TypeMulti.Value) : Convert.ToInt32(cmbProp10TypeColl.Value);

        config.Prop1DefaultValue = txtProp1DefaultValue.Text;
        config.Prop2DefaultValue = txtProp2DefaultValue.Text;
        config.Prop3DefaultValue = txtProp3DefaultValue.Text;
        config.Prop4DefaultValue = txtProp4DefaultValue.Text;
        config.Prop5DefaultValue = txtProp5DefaultValue.Text;
        config.Prop6DefaultValue = txtProp6DefaultValue.Text;
        config.Prop7DefaultValue = txtProp7DefaultValue.Text;
        config.Prop8DefaultValue = txtProp8DefaultValue.Text;
        config.Prop9DefaultValue = txtProp9DefaultValue.Text;
        config.Prop10DefaultValue = txtProp10DefaultValue.Text;

        if (config.ID > 0)
        {
            config.Update();
        }
        else
        {
            config.Insert();
        }

        return config;
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            ProductTypeConfig config = this.SaveConfig();
            Response.Redirect("ProductContent.aspx?action=view&g=" + Request.QueryString["g"] + "&typeid=" + Request.QueryString["typeid"] + "&time=" + DateTime.Now.Ticks.ToString(), false);
        }
        catch (Exception)
        {
            Response.Redirect("ProductContent.aspx?action=view&g=" + Request.QueryString["g"] + "&typeid=" + Request.QueryString["typeid"] + "&time=" + DateTime.Now.Ticks.ToString(), false);
        }
    }

    protected void btnSaveAllSub_Click(object sender, EventArgs e)
    {
        try
        {
            ProductTypeConfig config = this.SaveConfig();

            DataTable tb = ProductTypeConfig.GetAll(config.GroupID);
            if (tb != null)
            {
                foreach (DataRow row in tb.Rows)
                {
                    int id = (int)row[ProductTypeConfig.ID__COLUMN_NAME];
                    int typeID = (int)row[ProductTypeConfig.TYPEID__COLUMN_NAME];
                    config.ID = id;
                    config.TypeID = typeID;
                    config.Update();
                }
            }

            Response.Redirect("ProductContent.aspx?action=view&g=" + Request.QueryString["g"] + "&typeid=" + Request.QueryString["typeid"] + "&time=" + DateTime.Now.Ticks.ToString(), false);
        }
        catch (Exception)
        {
            Response.Redirect("ProductContent.aspx?action=view&g=" + Request.QueryString["g"] + "&typeid=" + Request.QueryString["typeid"] + "&time=" + DateTime.Now.Ticks.ToString(), false);
        }
    }
}
